package com.central.oauth2.common.store;

import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

/**
 * 认证服务器使用数据库存取令牌
 * 当 my-config.oauth2.token.store.type=db 的时候, 启用这个配置
 */
@ConditionalOnProperty(prefix = "my-config.oauth2.token.store", name = "type", havingValue = "db")
public class AuthDbTokenStore {

    @Autowired
    private DataSource dataSource;

    @Bean
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }
}
